import { DEFAULT_NAME } from '@/constants';

export default {
  namespace: 'global',
  state: {
    name: DEFAULT_NAME || 'Guest',
    loading: false,
  },
  effects: {
    *updateName({ payload }, { put }) {
      yield put({
        type: 'save',
        payload: {
          name: payload,
        },
      });
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    // 确保始终返回一个有效的状态
    default(state) {
      return state;
    },
  },
};